from typing import Optional
from datetime import datetime
from pydantic import BaseModel, ConfigDict
from uuid import UUID


class ReportHeaderBase(BaseModel):
    code: str
    name: str


class ReportHeaderCreate(ReportHeaderBase):
    pass


class ReportHeaderUpdate(BaseModel):
    name: str


class ReportHeaderRead(ReportHeaderBase):
    id: UUID
    adopted_version_id: Optional[UUID] = None
    model_config = ConfigDict(from_attributes=True, json_encoders={UUID: str})


class ReportVersionBase(BaseModel):
    report_id: UUID
    version_no: Optional[int] = None
    template_version_code: str
    title: str


class ReportVersionCreate(ReportVersionBase):
    pass


class ReportVersionUpdate(BaseModel):
    template_version_code: Optional[str] = None
    title: Optional[str] = None


class ReportVersionRead(BaseModel):
    id: UUID
    report_id: UUID
    version_no: int
    template_version_code: str
    title: str
    status: str
    adopted: bool
    mongo_report_id: Optional[str] = None
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
    model_config = ConfigDict(from_attributes=True, json_encoders={UUID: str})